package com.boroborome.convert;

import java.util.ArrayList;
import java.util.List;

public class StatisticItemBuilder {
    private String functionId;
    private double maxTime;
    private double totalTime;
    private long count;
    private List<Double> details = new ArrayList<>();

    public StatisticItemBuilder(String functionId) {
        this.functionId = functionId;
    }

    public void acceptRecord(ICallRecord record) {
        count++;
        maxTime = Math.max(maxTime, record.getTime());
        totalTime += record.getTime();
        details.add(record.getTime());
    }

    public StatisticItem build() {
        return new StatisticItem(functionId, totalTime / count, details.get(details.size() / 2), maxTime, count);
    }
}
